// 计算高差角
export function calcAngle(h: number, l: number) {
  const angle = Math.atan(h / l);
  return angle;
}

// 计算水平张力Hi
export function calcHi(
  w: number,
  n: number,
  l: number,
  N: number,
  y: number,
  angle: number,
) {
  const b = 2 * (N - y) * Math.cos(angle) + 2 * n * Math.sin(angle);
  const Hi = (w * n * (l - n)) / b;
  return Hi;
}

// 计算最大弧垂
export function calcF(l: number, w: number, Hi: number, angle: number) {
  const f = (l ** 2 * w) / 8 / Hi / Math.cos(angle);
  return f;
}

// 计算平视弧垂FB
export function calcFB(f: number, h: number) {
  const FB = f * (1 + h / 4 / f) ** 2;
  return FB;
}

// 通过FB计算TB
export function calcTBFromFB(Hi: number, w: number, FB: number, angle: number) {
  const TB = Hi + (w * FB) / Math.cos(angle);
  return TB;
}

// 通过TB计算TA
export function calcTAFromTB(TB: number, w: number, h: number, angle: number) {
  const TA = TB - (w * h) / Math.cos(angle);
  return TA;
}

// 通过TA计算TB
export function calcTBFromTA(
  TA: number,
  w: number,
  m: number,
  h: number,
  angle: number,
) {
  const TB = m * TA + (m * w * h) / Math.cos(angle);
  return TB;
}
// 通过TA计算水平张力Hi
export function calcHiFromTA(
  w: number,
  h: number,
  l: number,
  TA: number,
  angle: number,
) {
  const a = h ** 2 / 2 / l ** 2 + 1;
  const b = -TA - (w * h) / 2 / Math.cos(angle);
  const c = (l ** 2 * w ** 2) / 8 / Math.cos(angle) ** 2;
  const Hi = (-b + (b ** 2 - 4 * a * c) ** 0.5) / 2 / a;
  return Hi;
}

// 任意点弧垂公式
export function calcFx(w, x, l, Hi, angle) {
  const fx = (w * x * (l - x)) / 2 / Hi / Math.cos(angle);
  return fx;
}
